From 0fe79510ca146057b4041b922d88c4daebd75faf Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 9 Sep 2013 17:30:01 +0000 Subject: [PATCH] Remove explicit xstrdup(CSTR... in favor of helper. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4598 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/defs.h | 3 +++ gpsbabel/gpx.cc | 26 +++++++++++++------------- gpsbabel/html.cc | 2 +- gpsbabel/kml.cc | 2 +- gpsbabel/navicache.cc | 4 ++-- gpsbabel/text.cc | 2 +- gpsbabel/util.cc | 9 +++++++-- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index d17311e0e..b72cf1f26 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -38,6 +38,7 @@ #include #include +#include # include "src/core/datetime.h" @@ -216,6 +217,7 @@ extern const char gpsbabel_version[]; extern time_t gpsbabel_now; /* gpsbabel startup-time; initialized in main.c with time() */ extern time_t gpsbabel_time; /* gpsbabel startup-time; initialized in main.c with current_time(), ! ZERO within testo ! */ extern int geocaches_present; +extern QTextStream cerr; #define MILLI_TO_MICRO(t) (t * 1000) /* Milliseconds to Microseconds */ #define MICRO_TO_MILLI(t) (t / 1000) /* Microseconds to Milliseconds*/ @@ -920,6 +922,7 @@ void* xmalloc(size_t size); void* xrealloc(void* p, size_t s); void xfree(const void* mem); char* xstrdup(const char* s); +char* xstrdup(const QString& s); char* xstrndup(const char* s, size_t n); char* xstrndupt(const char* s, size_t n); char* xstrappend(char* src, const char* addon); diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index b0cec01f9..b623d25f2 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -218,7 +218,7 @@ gpx_add_to_global(gpx_global_entry* ge, const QString& s) gep = (gpx_global_entry*) xcalloc(sizeof(*gep), 1); QUEUE_INIT(&gep->queue); - gep->tagdata = xstrdup(CSTR(s)); + gep->tagdata = xstrdup(s); ENQUEUE_TAIL(&ge->queue, &gep->queue); } @@ -466,10 +466,10 @@ tag_gpx(const QXmlStreamAttributes& attr) * version. */ if (! gpx_version) { - gpx_version = xstrdup(CSTR(attr.value("version").toString())); + gpx_version = xstrdup(attr.value("version").toString()); } else if ((strtod(gpx_version, NULL) * 10) < (attr.value("version").toString().toDouble() * 10)) { xfree(gpx_version); - gpx_version = xstrdup(CSTR(attr.value("version").toString())); + gpx_version = xstrdup(attr.value("version").toString()); } } /* save namespace declarations in case we pass through elements @@ -557,9 +557,9 @@ start_something_else(const QString el, const QXmlStreamAttributes& attr) new_tag->attributes = (char**)xcalloc(sizeof(char*),2*attr_count+1); avcp = new_tag->attributes; for (int i = 0; i < attr_count; i++) { - *avcp = xstrdup(CSTR(attr[i].name().toString())); + *avcp = xstrdup(attr[i].name().toString()); avcp++; - *avcp = xstrdup(CSTR(attr[i].value().toString())); + *avcp = xstrdup(attr[i].value().toString()); avcp++; } *avcp = NULL; // this indicates the end of the attribute name value pairs. @@ -936,7 +936,7 @@ gpx_end(const QString& el) if (wpt_tmp->notes != NULL) { xfree(wpt_tmp->notes); } - wpt_tmp->notes = xstrdup(CSTR(cdatastr)); + wpt_tmp->notes = xstrdup(cdatastr); break; case tt_cache_container: waypt_alloc_gc_data(wpt_tmp)->container = gs_mkcont(cdatastr); @@ -1024,7 +1024,7 @@ gpx_end(const QString& el) * Route-specific tags. */ case tt_rte_name: - rte_head->rte_name = xstrdup(CSTR(cdatastr)); + rte_head->rte_name = xstrdup(cdatastr); break; case tt_rte: break; @@ -1040,7 +1040,7 @@ gpx_end(const QString& el) wpt_tmp = NULL; break; case tt_rte_desc: - rte_head->rte_desc = xstrdup(CSTR(cdatastr)); + rte_head->rte_desc = xstrdup(cdatastr); break; case tt_rte_number: rte_head->rte_num = cdatastr.toInt(); @@ -1049,7 +1049,7 @@ gpx_end(const QString& el) * Track-specific tags. */ case tt_trk_name: - trk_head->rte_name = xstrdup(CSTR(cdatastr)); + trk_head->rte_name = xstrdup(cdatastr); break; case tt_trk: break; @@ -1068,7 +1068,7 @@ gpx_end(const QString& el) wpt_tmp = NULL; break; case tt_trk_desc: - trk_head->rte_desc = xstrdup(CSTR(cdatastr)); + trk_head->rte_desc = xstrdup(cdatastr); break; case tt_trk_number: trk_head->rte_num = cdatastr.toInt(); @@ -1097,7 +1097,7 @@ gpx_end(const QString& el) case tt_wpt_name: case tt_rte_rtept_name: case tt_trk_trkseg_trkpt_name: - wpt_tmp->shortname = xstrdup(CSTR(cdatastr)); + wpt_tmp->shortname = xstrdup(cdatastr); break; case tt_wpt_sym: case tt_rte_rtept_sym: @@ -1112,7 +1112,7 @@ gpx_end(const QString& el) case tt_wpt_cmt: case tt_rte_rtept_cmt: case tt_trk_trkseg_trkpt_cmt: - wpt_tmp->description = xstrdup(CSTR(cdatastr)); + wpt_tmp->description = xstrdup(cdatastr); break; case tt_wpt_desc: case tt_trk_trkseg_trkpt_desc: @@ -1120,7 +1120,7 @@ gpx_end(const QString& el) if (wpt_tmp->notes != NULL) { xfree(wpt_tmp->notes); } - wpt_tmp->notes = xstrdup(CSTR(cdatastr)); + wpt_tmp->notes = xstrdup(cdatastr); break; case tt_pdop: wpt_tmp->pdop = cdatastr.toDouble(); diff --git a/gpsbabel/html.cc b/gpsbabel/html.cc index 89fa613b6..652052847 100644 --- a/gpsbabel/html.cc +++ b/gpsbabel/html.cc @@ -223,7 +223,7 @@ html_disp(const waypoint* wpt) if (html_encrypt && encoded) { s = rot13(logpart->cdata); } else { - s = xstrdup(CSTR(logpart->cdata)); + s = xstrdup(logpart->cdata); } t = html_entitize(s); diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc index a2f2e3e9c..baecac255 100644 --- a/gpsbabel/kml.cc +++ b/gpsbabel/kml.cc @@ -1358,7 +1358,7 @@ QString kml_geocache_get_logs(const waypoint* wpt) if (html_encrypt && encoded) { s = rot13(logpart->cdata); } else { - s = xstrdup(CSTR(logpart->cdata)); + s = xstrdup(logpart->cdata); } r = r + "
"; diff --git a/gpsbabel/navicache.cc b/gpsbabel/navicache.cc index 0588e88b3..04d464ba9 100644 --- a/gpsbabel/navicache.cc +++ b/gpsbabel/navicache.cc @@ -106,13 +106,13 @@ NaviReadCache(const QXmlStreamReader& reader) if (a.hasAttribute("cache_id")) { int n = a.value("cache_id").toString().toInt(); QString fn = QString("N%1").arg(n, 5, 16, QChar('0')); - wpt_tmp->shortname = xstrdup(CSTR(fn)); + wpt_tmp->shortname = xstrdup(fn); UrlLink l(QString(NC_URL) + QString::number(n)); wpt_tmp->AddUrlLink(l); } if (a.hasAttribute("name")) { - wpt_tmp->description = xstrdup(CSTR(a.value("name").toString())); + wpt_tmp->description = xstrdup(a.value("name").toString()); } if (a.hasAttribute("user_name")) { gc_data->placer = a.value("user_name").toString(); diff --git a/gpsbabel/text.cc b/gpsbabel/text.cc index 69e3e2a90..8e012eca3 100644 --- a/gpsbabel/text.cc +++ b/gpsbabel/text.cc @@ -232,7 +232,7 @@ text_disp(const waypoint* wpt) if (txt_encrypt && encoded) { s = rot13(logpart->cdata); } else { - s = xstrdup(CSTR(logpart->cdata)); + s = xstrdup(logpart->cdata); } gbfprintf(file_out, "%s", s); diff --git a/gpsbabel/util.cc b/gpsbabel/util.cc index 66583a438..581a8704e 100644 --- a/gpsbabel/util.cc +++ b/gpsbabel/util.cc @@ -149,6 +149,11 @@ xstrdup(const char* s) return o; } +char* xstrdup(const QString& s) +{ + return xstrdup(CSTR(s)); +} + /* * Duplicate at most sz bytes in str. */ @@ -1523,14 +1528,14 @@ strip_html(const utf_string* in) char tag[8]; unsigned short int taglen = 0; - incopy = instr = xstrdup(CSTR(in->utfstring)); + incopy = instr = xstrdup(in->utfstring); if (!in->is_html) { return instr; } /* * We only shorten, so just dupe the input buf for space. */ - outstring = out = xstrdup(CSTR(in->utfstring)); + outstring = out = xstrdup(in->utfstring); tag[0] = 0; while (*instr) { -- 2.30.2